package redis

import (
	goRedis "github.com/gomodule/redigo/redis"
)

type pool struct {
	pool   *goRedis.Pool
	option poolOption
}

func PoolStart(config ...setOption) Pool {
	pool := &pool{
		option: *defaultPoolOption(),
	}

	for _, v := range config {
		v.apply(&pool.option)
	}

	pool.pool = &goRedis.Pool{
		MaxIdle: pool.option.MaxIdle,
		Dial:    Redis.SetHost(pool.option.Host).Connect,
	}

	return pool
}

func (rev *pool) GetString() *str {
	return &str{
		conn: rev.pool.Get(),
	}
}

func (rev *pool) GetSet() *set {
	return &set{
		conn: rev.pool.Get(),
	}
}

func (rev *pool) GetHash() *hash {
	return &hash{
		conn: rev.pool.Get(),
	}
}

func (rev *pool) GetPing() *ping {
	return &ping{
		connect: rev.pool.Get(),
	}
}

func (rev *pool) GetKey() *key {
	return &key{
		connect: rev.pool.Get(),
	}
}
